import {severitiesCodes, facilitiesCodes, ntStatusCodes, win32ErrorCodes} from "../enum/ErrCode.js"
import {BigInt} from "./Bigint.js"
export default class StatusTool {
  static getStatus(errorCode) {
    var scode = errorCode
    var hex =
      '0x' + ('00000000' + scode).substr(-8);
    var err = ntStatusCodes[hex] ||
      win32ErrorCodes[hex] || {
        code: 'ERROR_UNRECOGNIZED',
        message: 'Unrecognized error',
      };
    err.value = errorCode;
    err.valueHex = hex;

    var facility = (errorCode >> 16) & 0x7ff;
    err.facility = facilitiesCodes[facility] || {
      code: 'FACILITY_UNRECOGNIZED',
      message: 'Unrecognized facility',
    };
    err.facility.value = facility;

    var severity = (errorCode >> 30) & 0x03;
    err.severity = severitiesCodes[severity] || {
      code: 'STATUS_UNRECOGNIZED',
      message: 'Unrecognized status',
    };
    err.severity.value = severity;

    return err;
  }

  static getErrorMessage(err) {
    return err.code + ' (' + err.valueHex + ') : ' + err.message;
  }
}
